<template>
  <div class="y-conter">
    
    <div class="y-biaoge">
      <h3 class="y-bold">车辆出入场记录</h3>
      <el-button @click="tiaotest()">录入车辆信息</el-button>
      <!-- 表格部分 -->
      <div class="y-table">
        <el-table
          :border="true"
          :header-cell-style="{ background: '#f5f7fa', color: '#606266' }"
          ref="multipleTable"
          :data="currList"
          tooltip-effect="dark"
          style="width: 98%, text-align: center "
          @selection-change="handleSelectionChange"
        >
          <!-- 序号 -->
          <el-table-column
            align="center"
            type="index"
            width="100"
            :index="indexFn"
            label="序号"
          ></el-table-column>
          <el-table-column
            label="时间"
            prop="carinfo_start"
          
            hight="30px"
            align="center"
          ></el-table-column>
          <el-table-column
            label="车牌号"
            prop="carinfo_number"
           
            align="center"
          ></el-table-column>
          <el-table-column
            label="车辆类型"
           
            prop="carinfo_type"
            align="center"
          ></el-table-column>
          <el-table-column
            label="状态"
         
            prop="carinfo_status"
            align="center"
          >
           <template slot-scope="scope">
            {{ scope.row.carinfo_status === 0 ?  '进入工地': '' }}
            {{ scope.row.carinfo_status === 1 ?  '离开工地': '' }}
        </template>
          </el-table-column>
          <el-table-column
            label="种类"
            width="172"
            prop="carinfo_kind"
            align="center"
          >
            <template slot-scope="scope">
            {{ scope.row.carinfo_status === 0 ?  '外部车辆': '' }}
            {{ scope.row.carinfo_status === 1 ?  '内部车辆': '' }}
        </template>
          </el-table-column>
              <el-table-column label="车辆照片" prop="carinfo_url" align="center" width="200px">
    					<template slot-scope="scope">
    						<el-popover placement="top-start" trigger="click">
    							<!--trigger属性值：hover、click、focus 和 manual-->
    							<a :href="scope.row.carinfo_url" target="_blank" title="查看最大化图片"><img :src="scope.row.carinfo_url" style="width: 300px;height: 300px" /></a>
    							<img slot="reference" :src="scope.row.carinfo_url" style="width: 50px;height: 50px; cursor:pointer" />
    						</el-popover>
    					</template>
    				</el-table-column>
        </el-table>   
      </div>
      <!-- 分页器 -->
      <div class="y-fenye">
        <el-pagination
          background
          layout="prev, pager, next"
          :total="tableData.length"
          :page-size="pageSize"
          @current-change="changePage"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
// import axios from "axios";
import http from "../api";
export default {
  data() {
    return {
      // url: "",

      // srcList: [],
      //搜索输入框
      ruleForm: {
        carinfo_kind: "", //种类
        carinfo_url: "", //车辆照片
        carinfo_status: "", //状态
        carinfo_number: "", //车牌号
        carinfo_start: "", //时间
        carinfo_type: "", //车辆类型
      },
      //多选表格的复选框
      multipleSelection: [],
      // 分页
      tableData: [], //总数居
      currPage: 1, //当前页
      pageSize: 5, //每页数据量
      currList: [], //当前展示的数据数组
      pickerOptions1: {
        //  日期
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      value1: "",
      value2: "",
    };
  },
  computed: {},

  methods: {
    // 跳转到添加车辆信息
    tiaotest(){
      this.$router.push({
        name:"导航"
      })
    },
    // 新增
    Newadditions() {
      this.$router.push({
        name: "新增车辆信息",
      });
    },
    // 分页
    setCurrList(index) {
      this.currList = this.tableData.slice(
        (index - 1) * this.pageSize,
        index * this.pageSize
      );
      // console.log('当前页',index);
    },
    //改变当前页
    changePage(val) {
      this.currPage = val;
      this.setCurrList(val);

      // console.log(val);
    },
    // 表格序号
    indexFn(index) {
      index = index + 1 + (this.currPage - 1) * this.pageSize;
      return index;
    },
    //重置按钮
    resetForm(formName) {
      this[formName] = {};
      this.$refs[formName].resetFields();
    },

    //表格编辑按钮
    handleEdit(index, row) {
      // console.log(index, row);
    },

    // // 表格删除按钮弹框
    // showConfirm() {
    //   this.$confirm({
    //     title: "确定删除班组信息吗?",
    //     content: (h) => <div style="color:red;">Some descriptions</div>,
    //     onOk() {
    //       console.log("OK");
    //     },
    //     onCancel() {
    //       console.log("Cancel");
    //     },
    //     class: "test",
    //   });
    // },

    //选中复选框获取下标
    handleSelectionChange(val) {
      // this.multipleSelection = val;
      // let ids = [];
      // this.multipleSelection.map((item) => {
      //   ids.push(item.key);
      // });
      // this.selectedIDs = ids;
      // console.log("你点击的是", this.selectedIDs);
    },
  },
  //获取数据
  mounted() {
    http.lineage({}).then((r) => {
      console.log(r);
      this.tableData = r.data;
      console.log(r.data);
      // let arr = r.data.map((item, index, arr1) => {
      //   return item.carinfo_url;
      // });
      // this.srcList = arr;
      // console.log("图片路径", this.srcList);
      this.setCurrList(1);
    });
    //
  },
};
</script>
<style scoped>
/* 大容器 */
.y-conter {
  height: 640px;
  background-color: white;
  overflow: hidden;
  overflow-y: scroll;
  margin-top: 15px;
}
/* 表格 */
.y-biaoge {
  margin-top: 20px;
  margin-left: 10px;
}

.y-table {
  margin-top: 15px;
}
/* 右侧新增导出按钮 */
.y-btn {
  position: absolute;
  top: 164px;
  left: 94%;
}
/* 所有按钮 */
.el-button {
  height: 30px;
  line-height: 0px;
}
/* 标题字体 */
.y-bold {
  font-weight: bold;
}
/* 输入框部分样式 */
.el-select >>> .el-input__inner {
  width: 178px;
  height: 30px;
}
.el-input >>> .el-input__inner {
  width: 178px;
  height: 30px;
}
.el-range-editor {
  width: 160px;
  height: 30px;
  padding-left: 10px;
}
.el-input >>> .el-range__icon {
  line-height: 0px;
  padding-left: 10px;
}
.el-range-editor >>> .el-input__inner {
  width: 200px;
  height: 30px;
  margin-top: 10px;
}
/* 分页 */
.y-fenye {
  float: right;
  margin-top: 20px;
}
/* 新增 */

.el-form-item {
  margin-bottom: 2px !important;
}
</style>